package terra.model;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import terra.Loader;
import terra.network.packet.client.RequestUseItem;
import terra.slick.GameState;

public class InventoryState {

	public ItemClientDef[] slotItems = new ItemClientDef[Slot.SLOT_COUNT];
	public int constructable = -1;
	public int maxCount = 18;
	public ShortCut[] shortcuts = new ShortCut[10];
	private Map<Integer,ItemClientDef> inventoryItems = new ConcurrentHashMap<Integer,ItemClientDef>();
	
	public  Map<Integer,ItemClientDef> getInventoryItems() {
		return inventoryItems;
	}
	
	public void registerShortcut(ShortCut c, int pos) {
		shortcuts[pos] = c;
	}

	public void useShorCut(int i) {
		if (shortcuts[i]== null)
			return;
		RequestUseItem request = new RequestUseItem(GameState.getInstance().player.getObjectId(),shortcuts[i].getOId(), shortcuts[i].getId());
		Loader.handler.send(request);
	}

	public void useItem(int objectId,int itemId) {
		RequestUseItem request = new RequestUseItem(GameState.getInstance().player.getObjectId(),objectId, itemId);
		Loader.handler.send(request);
	}

//	public int containsItem(int oId) {
//		return getInventoryItems().indexOf(item);
////		for(int i = 0; i < getInventoryItems().size();i++)
////			if(i < inventoryItems.size() && inventoryItems.get(i) != null && inventoryItems.get(i).getOId() == oId)
////				return i;
//		return -1;
//	}
	
	public ItemClientDef getItem(int oId) {
		return getInventoryItems().get(oId);
	}

	public void clear() {
		getInventoryItems().clear();
		slotItems = new ItemClientDef[Slot.SLOT_COUNT];
		shortcuts = new ShortCut[10];
		constructable = -1;
	}
}
